package org.one.afternoon.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.one.afternoon.common.DayOfTheWeek;
import org.one.afternoon.common.Result;
import org.one.afternoon.domain.Statistic;
import org.one.afternoon.service.HospitalService;
import org.one.afternoon.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/statistic")
public class StatisticController {

    @Autowired
    private StatisticService statisticService;

    @Autowired
    private HospitalService hospitalService;

    @CrossOrigin
    @GetMapping("/card")
    public Result<Long> queryCard(@RequestParam String type) {
        LambdaQueryWrapper<Statistic> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        long count = statisticService.count(lambdaQueryWrapper);
        lambdaQueryWrapper.eq(Statistic::getId, count);
        Statistic one = statisticService.getOne(lambdaQueryWrapper);
        if (type.equals("volunteer")) {
            return Result.success(one.getVolunteerNum());
        } else if (type.equals("veteran")) {
            return Result.success(one.getVeteranNum());
        } else if (type.equals("needy")) {
            return Result.success(one.getNeedyNum());
        }
        return Result.success(one.getRetiredNum());
    }

    @CrossOrigin
    @GetMapping("/bill")
    public Result<List<Long>> queryTotalBills() {
        List<Long> list = DayOfTheWeek.twoWeeksList("bill", statisticService, hospitalService);
        return Result.success(list);
    }

    @CrossOrigin
    @RequestMapping("/list")
    public Result<List<Long>> queryCardList(@RequestParam String type){
        List<Long> list = DayOfTheWeek.twoWeeksList(type, statisticService, hospitalService);
        return Result.success(list);
    }

}
